package com.zzy.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zzy.domain.dto.WarehousePageDto;
import com.zzy.domain.po.Warehouse;
import com.zzy.domain.vo.PageResult;
import com.zzy.mapper.WarehouseMapper;
import com.zzy.service.WarehouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class WarehouseServiceImpl extends ServiceImpl<WarehouseMapper, Warehouse> implements WarehouseService {
    @Autowired
    private WarehouseMapper warehouseMapper;


    @Override
    public Integer delByIds(List<Long> ids) {
       return warehouseMapper.deleteByIds(ids);

    }

    @Override
    public PageResult<Warehouse> getpage(WarehousePageDto dto) {

        Page<Warehouse> page = new Page<>(dto.getPage(), dto.getPageSize());

        // 构建查询条件
        LambdaQueryWrapper<Warehouse> wrapper = new LambdaQueryWrapper<>();
        wrapper.like(StrUtil.isNotEmpty(dto.getName()), Warehouse::getName, dto.getName())
                .eq(StrUtil.isNotEmpty(dto.getCityName()), Warehouse::getCityName, dto.getCityName())
                .like(StrUtil.isNotEmpty(dto.getPersonChargeName()),
                        Warehouse::getPersonChargeName, dto.getPersonChargeName());

        // 执行分页查询
        Page<Warehouse> result = this.page(page, wrapper);

        // 返回封装的分页结果，包含总记录数和当前页数据
        return new PageResult<>(result.getTotal(), result.getRecords());
    }
//
//    @Service
//    public class WarehouseServiceImpl extends ServiceImpl<WarehouseMapper, Warehouse> implements WarehouseService {
//        @Autowired
//        private WarehouseMapper warehouseMapper;
//        @Override
//        public List<Warehouse> getpage(WarehousePageDto warehousePageDto) {
//            Long total=warehouseMapper.selectCount(null);
//            //分页
//            Page<Warehouse> page = new Page<>(warehousePageDto.getPage(), warehousePageDto.getPageSize());
//            LambdaQueryWrapper<Warehouse>ware=new LambdaQueryWrapper<>();
//            ware.like(StrUtil.isNotEmpty(warehousePageDto.getName()),Warehouse::getName,warehousePageDto.getName());
//            ware.eq(StrUtil.isNotEmpty(warehousePageDto.getCityName()),Warehouse::getCityName,warehousePageDto.getCityName());
//            ware.like(StrUtil.isNotEmpty(warehousePageDto.getPersonChargeName()),Warehouse::getPersonChargeName,warehousePageDto.getPersonChargeName());
//            List<Warehouse>list=warehouseMapper.selectList(page,ware);
//            return new PageResult<Warehouse>(total,list);
//        }


}
